home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dosrcss.zip / RCSMERGE.C < prev    next >
C/C++ Source or Header  |  1990-07-18  |  10KB  |  295 lines

  1. /*
  2.  *                       rcsmerge operation
  3.  */
  4. #ifndef lint
  5. static char rcsid[]=
  6. "$Header: /site/tmp/dosrcs/src/RCS/rcsmerge.c,v 5.5 90/07/16 21:39:57 lfk Release $ Purdue CS";
  7. #endif
  8. /*****************************************************************************
  9.  *                       join 2 revisions with respect to a third
  10.  *****************************************************************************
  11.  */
  12.  
  13. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  14.    Distributed under license by the Free Software Foundation, Inc.
  15.  
  16. This file is part of RCS.
  17.  
  18. RCS is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 1, or (at your option)
  21. any later version.
  22.  
  23. RCS is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. GNU General Public License for more details.
  27.  
  28. You should have received a copy of the GNU General Public License
  29. along with RCS; see the file COPYING.  If not, write to
  30. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  
  32. Report problems and direct all questions to:
  33.  
  34.     rcs-bugs@cs.purdue.edu
  35.  
  36. */
  37.  
  38.  
  39.  
  40. /* $Log:    rcsmerge.c,v $
  41.  * Revision 5.5  90/07/16  21:39:57  lfk
  42.  * checkin for release compilation
  43.  * 
  44.  * Revision 5.4  90/07/15  22:55:32  lfk
  45.  * Almost the end of major revison for MS-DOS version of RCS
  46.  * 
  47.  * Revision 5.3  90/07/15  20:25:43  lfk
  48.  * Most major fixes added between rev 5.1 and rev 5.5:
  49.  *     signals fixed so they work on MS-DOS
  50.  *     Added MKS arguments code so argv can be large
  51.  *     added code to handle slashes a'la Unix
  52.  *     added more file extensions to system from MS-DOS
  53.  * 
  54.  * Revision 5.2  90/07/15  11:34:31  ROOT_DOS
  55.  * DOS version of RCS 4.0 checked in for MODS
  56.  * by lfk@athena.mit.edu
  57.  * Also update to MSC 6.0
  58.  * 
  59.  * Revision 4.5  89/05/01  15:13:16  narten
  60.  * changed copyright header to reflect current distribution rules
  61.  * 
  62.  * Revision 4.4  88/11/08  12:00:47  narten
  63.  * changes from  eggert@sm.unisys.com (Paul Eggert)
  64.  * 
  65.  * Revision 4.4  88/08/09  19:13:13  eggert
  66.  * Beware merging into a readonly file.
  67.  * Beware merging a revision to itself (no change).
  68.  * Use execv(), not system(); yield exit status like diff(1)'s.
  69.  * 
  70.  * Revision 4.3  87/10/18  10:38:02  narten
  71.  * Updating version numbers. Changes relative to version 1.1 
  72.  * actually relative to 4.1
  73.  * 
  74.  * Revision 1.3  87/09/24  14:00:31  narten
  75.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  76.  * warnings)
  77.  * 
  78.  * Revision 1.2  87/03/27  14:22:36  jenkins
  79.  * Port to suns
  80.  * 
  81.  * Revision 1.1  84/01/23  14:50:36  kcs
  82.  * Initial revision
  83.  * 
  84.  * Revision 4.1  83/03/28  11:14:57  wft
  85.  * Added handling of default branch.
  86.  * 
  87.  * Revision 3.3  82/12/24  15:29:00  wft
  88.  * Added call to catchsig().
  89.  *
  90.  * Revision 3.2  82/12/10  21:32:02  wft
  91.  * Replaced getdelta() with gettree(); improved error messages.
  92.  *
  93.  * Revision 3.1  82/11/28  19:27:44  wft
  94.  * Initial revision.
  95.  *
  96.  */
  97. #include "rcsbase.h"
  98. #ifndef lint
  99. static char rcsbaseid[] = RCSBASE;
  100. #endif
  101. static char co[] = CO;
  102. static char merge[] = MERGE;
  103.  
  104. extern int  cleanup();              /* cleanup after signals                */
  105. extern char * mktempfile();         /*temporary file name generator         */
  106. extern struct hshentry * genrevs(); /*generate delta numbers                */
  107. extern int  nerror;                 /*counter for errors                    */
  108.  
  109. #ifdef MSDOS
  110. extern char *getmpdir();
  111. char    tmpdir[NCPPN];
  112. #endif /* MSODS */
  113.  
  114. char *RCSfilename;
  115. char *workfilename;
  116. char * temp1file, * temp2file;
  117.  
  118. #ifdef MKS
  119. main( int argc, char * argv[], char * env[] )
  120. #else
  121. main( argc, argv )
  122. int argc;
  123. char *argv[];
  124. #endif /* MKS Startup Args */
  125. {
  126.         char * cmdusage;
  127.         int  revnums; /* counter for revision numbers given */
  128.         int tostdout;
  129.     int nochange;
  130.         char * rev1, * rev2; /*revision numbers*/
  131.     char commarg[revlength+3];
  132.         char numericrev[revlength];   /* holds expanded revision number     */
  133.         struct hshentry * gendeltas[hshsize];/*stores deltas to be generated*/
  134.         struct hshentry * target;
  135. #ifdef MKS
  136.     int z = 0;
  137.     int ARGC = 0;
  138.     char **tmp;
  139.     char *env_name;
  140. #    define MAXARGS 500        /* This means 500 items on the command line */
  141.     if (!(tmp = (char **)malloc(sizeof(char *)*(MAXARGS+1)))) {
  142.         fprintf(stderr, "%s: can't allocate space for arguments\n",argv[0]);
  143.         exit(1);
  144.     }
  145.     for ( z = 0 ; env[z] != NULL; z++) {    /* loop through environment */
  146.         if (*env[z] == '~') {    /* testing for entries begining with '~' */
  147.             *++env[z];            /* increment pointer to delete '~' */
  148.             tmp[ARGC++] = env[z];    /* add it to our new array */
  149.             if (z >= MAXARGS) {
  150.                 fprintf(stderr, "%s: can't handle any more arguments\n", argv[0]);
  151.                 goto list;
  152.             }
  153.         }
  154.         else if (*env[z] == '_') {    /* testing for entries begining with _ */
  155.             *++env[z] ; *++env[z];    /* move past the '_' and the '=' */
  156.             env_name = env[z];    /* copy the name */
  157.         }
  158.     }
  159. list:
  160.     if ( STREQ( (char *) argv[0] , env_name ) ) {    /* test name against startup args */
  161.         /* environment arguments meant for this program */
  162. #    ifdef DEBUG
  163.         printf("Using shell supplied args\n");
  164. #    endif
  165.         argc = ARGC;
  166.         tmp[ARGC] = NULL;    /* the terminal NULL */
  167.         argv = tmp;
  168.     }
  169. #    ifdef DEBUG
  170.     else 
  171.         printf("Using startup supplied args\n");
  172. #    endif /* debug */
  173. #endif /* MKS */
  174.  
  175.         catchints();
  176.         cmdid = "rcsmerge";
  177.         cmdusage = "command format:\n    rcsmerge -p -rrev1 -rrev2 file\n    rcsmerge -p -rrev1 file";
  178.     revnums=0;tostdout=false;nochange=false;
  179.  
  180.         while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
  181.                 switch ((*argv)[1]) {
  182.                 case 'p':
  183.                         tostdout=true;
  184.                         /* falls into -r */
  185.                 case 'r':
  186.                         if ((*argv)[2]!='\0') {
  187.                             if (revnums==0) {
  188.                                     rev1= *argv+2; revnums=1;
  189.                             } elif (revnums==1) {
  190.                                     rev2= *argv+2; revnums=2;
  191.                             } else {
  192.                                     faterror("too many revision numbers");
  193.                             }
  194.                         } /* do nothing for empty -r or -p */
  195.                         break;
  196.  
  197.                 default:
  198.                         faterror("unknown option: %s\n%s", *argv,cmdusage);
  199.                 };
  200.         } /* end of option processing */
  201.  
  202.         if (argc<1) faterror("No input file\n%s",cmdusage);
  203.         if (revnums<1) faterror("no base revision number given");
  204.  
  205. #ifdef MSDOS
  206.     strcpy( tmpdir, (char *) gettmpdir() );
  207. #endif /* MSDOS */
  208.  
  209.         /* now handle all filenames */
  210.  
  211.         if (pairfilenames(argc,argv,true,false)==1) {
  212.  
  213.                 if (argc>2 || (argc==2&&argv[1]!=nil))
  214.                         warn("too many arguments");
  215.                 diagnose("RCS file: %s",RCSfilename);
  216.         if (!(access(workfilename,tostdout?4:6)==0))
  217.             nowork();
  218.  
  219.                 if (!trysema(RCSfilename,false)) goto end; /* give up */
  220.  
  221.                 gettree();  /* reads in the delta tree */
  222.  
  223.                 if (Head==nil) faterror("no revisions present");
  224.  
  225.  
  226.                 if (!expandsym(rev1,numericrev)) goto end;
  227.                 if (!(target=genrevs(numericrev, (char *)nil, (char *)nil, (char *)nil,gendeltas))) goto end;
  228.                 rev1=target->num;
  229.                 if (revnums==1)  /*get default for rev2 */
  230.                         rev2=Dbranch!=nil?Dbranch->num:Head->num;
  231.                 if (!expandsym(rev2,numericrev)) goto end;
  232.                 if (!(target=genrevs(numericrev, (char *)nil, (char *)nil, (char *)nil,gendeltas))) goto end;
  233.                 rev2=target->num;
  234.  
  235.         if (strcmp(rev1,rev2) == 0) {
  236.             diagnose("Merging revision %s to itself (no change)",
  237.                 rev1
  238.             );
  239.             nochange = true;
  240.             if (tostdout) {
  241.                 FILE *w = fopen(workfilename,"r");
  242.                 if (w==NULL)
  243.                     nowork();
  244.                 fastcopy(w,stdout);
  245.             }
  246.             goto end;
  247.         }
  248.  
  249. #ifdef MSDOS
  250.                 temp1file=mktempfile(tmpdir,TMPFILE1);
  251.                 temp2file=mktempfile(tmpdir,TMPFILE2);
  252. #else
  253.                 temp1file=mktempfile("/tmp/",TMPFILE1);
  254.                 temp2file=mktempfile("/tmp/",TMPFILE2);
  255. #endif /* MSDOS */
  256.  
  257.                 diagnose("retrieving revision %s",rev1);
  258.                 VOID sprintf(commarg,"-p%s",rev1);
  259.                 if (run((char*)nil,temp1file, co,"-q",commarg,RCSfilename,(char*)nil)){
  260.                         faterror("co failed");
  261.                 }
  262.                 diagnose("retrieving revision %s",rev2);
  263.                 VOID sprintf(commarg,"-p%s",rev2);
  264.                 if (run((char*)nil,temp2file, co,"-q",commarg,RCSfilename,(char*)nil)){
  265.                         faterror("co failed");
  266.                 }
  267.                 diagnose("Merging differences between %s and %s into %s%s",
  268.                          rev1, rev2, workfilename,
  269.                          tostdout?"; result to stdout":"");
  270.  
  271.                 if (
  272.               tostdout
  273. #if defined(MSDOS) && defined(MKS)
  274.             ? run((char*)nil,(char*)nil,"sh",merge,"-p",workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)
  275.             : run((char*)nil,(char*)nil,"sh",merge,     workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)) {
  276. #else
  277.             ? run((char*)nil,(char*)nil,merge,"-p",workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)
  278.             : run((char*)nil,(char*)nil,merge,     workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)) {
  279. #endif
  280.                         faterror("merge failed");
  281.                 }
  282.         }
  283.  
  284. end:
  285.         VOID cleanup();
  286.     exit(2*(nerror!=0) + nochange);
  287.  
  288. }
  289.  
  290.  
  291. nowork()
  292. {
  293.     faterror("Can't open %s",workfilename);
  294. }
  295.